<?php

use Illuminate\Database\Seeder;
use App\Models\Site;
use App\Models\User;

class SitesTableSeeder extends Seeder
{
    public function run()
    {
        // 所有用户 ID
        $user_ids = User::all()->pluck('id')->toArray();

        $faker = app(Faker\Generator::class);

        $sites = factory(Site::class)
                    ->times(100)
                    ->make()
                    ->each(function ($site, $index) use ($user_ids, $faker) {
                        $site->user_id = $faker->randomElement($user_ids);
                    });

        Site::insert($sites->toArray());
    }

}
